package com.ptrsystem.siatd.controllers;

import com.ptrsystem.siatd.dao.logica.ConsultasTdLogica;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ConsultasTdController {

    @Autowired
    private ConsultasTdLogica log;

    @RequestMapping(value = "detDocumentoRef.htm", method = RequestMethod.POST)
    private void detDocumentoRef(HttpServletResponse res, HttpServletRequest req) throws IOException {
        PrintWriter out = res.getWriter();
        List<Map> lista = log.getDetDocumentoReferencia(req.getParameter("dni"));
        String rs = "";
        for (int i = 0; i < lista.size(); i++) {
            rs += "<tr id='" + lista.get(i).get("nroEmiDocAdm") + "'>"
                    + "<td>" + lista.get(i).get("nroEmiDocAdm") + "</td>"
                    + "<td>" + lista.get(i).get("tipDoc") + "</td>"
                    + "<td>" + lista.get(i).get("nomTipDoc") + "</td>"
                    + "<td>" + lista.get(i).get("asu") + "</td>"
                    + "<td>" + lista.get(i).get("fec") + "</td>"
                    + "<td>" + lista.get(i).get("ani") + "</td>"
                    + "<td>" + lista.get(i).get("des") + "</td>"
                    + "<td>" + lista.get(i).get("uniPad") + "</td>"
                    + "<td>" + lista.get(i).get("uniDep") + "</td>"
                    + "<td>" + lista.get(i).get("rutDoc") + "</td>"
                    + "<td><button  value='" + lista.get(i).get("nroEmiDocAdm") + "' type='button' onclick='selectDocRef(this.value);'>select</button></td>"
                    + "</tr>";
        }
        out.print(rs);
        out.close();
    }

    @RequestMapping(value = "busDocPersonales.htm", method = RequestMethod.POST)
    private void busDocPersonal(HttpServletResponse res, HttpServletRequest req) throws IOException {
        PrintWriter out = res.getWriter();
        List<Map> lista = log.getBusDocPersonales(req.getParameter("dni"),
                req.getParameter("tipDoc"), req.getParameter("asu"), req.getParameter("fec"),
                req.getParameter("uniPad"), req.getParameter("uniDep"));
        String rs = "";
        for (int i = 0; i < lista.size(); i++) {
            rs += "<tr id='" + lista.get(i).get("numDoc") + "'>"
                    + "<td>" + lista.get(i).get("numDoc") + "</td>"
                    + "<td>" + lista.get(i).get("tipDoc") + "</td>"
                    + "<td>" + lista.get(i).get("nomDoc") + "</td>"
                    + "<td>" + lista.get(i).get("asu") + "</td>"
                    + "<td>" + lista.get(i).get("fec") + "</td>"
                    + "<td>" + lista.get(i).get("usuDes") + "</td>"
                    + "<td>" + lista.get(i).get("uniPad") + "</td>"
                    + "<td>" + lista.get(i).get("uniDep") + "</td>"
                    + "<td>" + lista.get(i).get("ani") + "</td>"
                    + "<td>" + lista.get(i).get("estDoc") + "</td>"
                    + "<td>" + lista.get(i).get("rutDoc") + "</td>"
                    + "<td><button  value='" + lista.get(i).get("numDoc") + "' type='button' onclick='selectDocRef(this.value);'>select</button></td>"
                    + "</tr>";
        }
        out.print(rs);
        out.close();

    }
}
